var uid, ws, daifukuan = 0;
document.addEventListener('plusready',function(){
	uid = plus.storage.getItem('uid');
	ws = plus.webview.currentWebview();
	PullToRefresh(ws);
	showWating();
	console.log(apiRoot+"?m=home&c=medicinal&a=orderList&uid="+uid+"&pati="+1)
	$.ajax({
		type :"get",
		url :apiRoot+"?m=home&c=medicinal&a=orderList&uid="+uid+"&pati="+1,
		success :function(data){
			plus.storage.setItem('predata',data);
			var data = $.parseJSON(data);
			plus.nativeUI.closeWaiting();
//			console.log(JSON.stringify(data));
			if(data.length > 0){ 
				var list = '';
				$.each(data, function(k,v){
//					console.log(JSON.stringify(v.status));
					if(v.status == 0){
						daifukuan++;
					}
					list += '<div class="mui-table-view table-view-cell bbs-ico" data-id="'+v.id+'" did="'+v.dinfo.aid+'">'+
									'<div class="overflow-h">'+
										'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
										'<div>'+
											'<li>'+
												'<span>'+v.binfo.name+'</span>'+
												'<span class="mui-h6 inquiry-right">';
										switch(v.status){
											case '0':list += '待付款';break;
											case '1':list += '待接单';break;
											case '2':list += '待收货';break;
											case '3':list += '已完成';break;
										}
										list += '</span>'+
											'</li>'+
											'<li class="mui-h6 ">'+
												'<span>'+v.ztime+'</span>'+
											'</li>'+
										'</div>'+
									'</div>'+ 
								'</div>';
				})
				$('.MyList').html(list); 
				$('.bbs-ico').unbind('tap');
				$('.bbs-ico').on('tap', function(){
					var id = $(this).attr('data-id');
					var did = $(this).attr('did');//医生Id
					goNewPage('me--prescription-inf.html',{aid:id,did:did,spage:ws.id})
				})
//				alert('您有'+daifukuan+'条药单待付款');
			}else{
				toast('暂无订单信息！');
			}
		},
		error :function(){
			console.log(JSON.stringify(e));
			errortoast();
			var dat = plus.storage.getItem('predata');
			var data = $.parseJSON(dat);
			if(data){
				console.log(JSON.stringify(data));
				var list = '';
				$.each(data, function(k,v) {
					list += '<div class="mui-table-view table-view-cell bbs-ico" data-id="'+v.id+'" did="'+v.dinfo.aid+'">'+
								'<div class="overflow-h">'+
									'<i><img src="'+getAvatar(v.binfo.avatar)+'"/></i>'+
									'<div>'+
										'<li>'+
											'<span>'+v.binfo.name+'</span>'+
											'<span class="mui-h6 inquiry-right">已完成</span>'+
										'</li>'+
										'<li class="mui-h6 ">'+
											'<span>'+v.ztime+'</span>'+
										'</li>'+
									'</div>'+
								'</div>'+
							'</div>';
				});
				$('.orderList').html(list);
				$('.bbs-ico').click(function(){
					var id = $(this).attr('data-id');
					var did = $(this).attr('did');//医生Id
					goNewPage('me--prescription-inf.html',{aid:id,did:did,spage:ws.id})
				})
			}
		}
	});
},false)